package com.bawei.live.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bawei.live.databinding.ItemGlobalFlashLayoutBinding
import com.bawei.live.databinding.ItemGlobalFocusTypeBinding
import com.bawei.live.entity.UserEntity

/**
 * @author: 王奎
 * @date: 2025/2/18
 */
class GoodsSaleAdapter constructor(private val list:MutableList<UserEntity>):RecyclerView.Adapter<GoodsSaleAdapter.ItemViewHodelr>(){

    private var itemClickListener:OnItemClickListener? = null

    interface OnItemClickListener{
        fun onItemClick(v: View, positions:Int)
    }
    fun setOnItemClickListener(listener:OnItemClickListener){
        itemClickListener = listener
    }
    inner class ItemViewHodelr(val dataBinding:ItemGlobalFocusTypeBinding):RecyclerView.ViewHolder(dataBinding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHodelr {
        var itemDataBinding = ItemGlobalFocusTypeBinding.inflate(LayoutInflater.from(parent.context),parent,false)
        return ItemViewHodelr(itemDataBinding)
    }

    override fun getItemCount(): Int = list.size

    override fun onBindViewHolder(holder: ItemViewHodelr, position: Int) {

        val entity = list[position]
        //设置排名
        holder.dataBinding.tvCount.text = entity.textCount.toString()
        //设置称呼
        holder.dataBinding.tvChenhu.text = entity.userName
        //设置分类
        holder.dataBinding.textView6.text = entity.goodsType
        //设置热度
        holder.dataBinding.tvHot.text = "${entity.hotDegree}热度"

        holder.dataBinding.tvClt.setOnClickListener{
            itemClickListener?.onItemClick(it,position)
        }


    }


}